//
//  YGScienceCenterHeaderView.m
//  yuanshangyiliao
//
//  Created by icholab on 2021/4/23.
//

#import "YGScienceCenterHeaderView.h"

@interface YGScienceCenterHeaderView ()

@property (nonatomic, strong) UIButton *commonBtn;
@property (nonatomic, strong) UILabel *commonLabel;


@end

@implementation YGScienceCenterHeaderView


- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self initView];
        [self initconstraints];
    }
    return self;
}

-(void)initView{
    [self addSubview:self.commonBtn];
    [self addSubview:self.commonLabel];
}

-(void)initconstraints{
    [self.commonBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.top.left.right.mas_equalTo(self);
        make.height.mas_equalTo(self).offset(-22);
    }];
    
    [self.commonLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(self.commonBtn.mas_bottom).offset(10);
            make.width.mas_equalTo(self.commonBtn.mas_width);
            make.height.mas_equalTo(12);
    }];
}

- (void)clickAction{
    
}

- (void)configureModel:(YGScienceCenterArticleModel *)model{
    
    [self setCommonBtnWithBackgroundImg:model.fileUrl addTarget:@selector(clickAction) text:model.theme];
}

-(void)setCommonBtnWithBackgroundImg:(NSString *)img
                           addTarget:(SEL)target
                                text:(NSString *)text{
    NSString *url = img;
    NSURL *urlImg = [NSURL URLWithString:url];
    [self.commonBtn sd_setBackgroundImageWithURL:urlImg forState:UIControlStateNormal];
    
    [self.commonBtn addTarget:self action:target forControlEvents:UIControlEventTouchUpInside];
    self.commonLabel.text = text;
}

#pragma setter

- (UIButton *)commonBtn{
    if (!_commonBtn) {
        _commonBtn = [[UIButton alloc]init];
    }
    return _commonBtn;
}

- (UILabel *)commonLabel{
    if (!_commonLabel) {
        _commonLabel = [[UILabel alloc]init];
        _commonLabel.font = [UIFont systemFontOfSize:12];
        _commonLabel.textColor = UIColorFromRGB(0x333333);
    }
    return _commonLabel;
}


/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
